package com.qinge.blog.controller;

import com.qinge.blog.entity.BlogCategory;
import com.qinge.blog.utils.CurrentUserUtil;
import com.qinge.blog.service.BlogCategoryService;
import com.qinge.blog.utils.result.JsonResult;
import com.qinge.blog.utils.result.ResultTool;
import com.qinge.blog.vo.BaseIdReqVO;
import com.qinge.blog.vo.BaseIdsReqVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author QDW
 * @date 2022/5/13 15:15
 * @description 目录
 **/
@RestController
@RequestMapping("/blog/api/category")
public class BlogCategoryController   {

    @Resource
    private BlogCategoryService categoryService;

    @PostMapping("/add")
    public JsonResult add(BlogCategory category){
        categoryService.add(category);

        return ResultTool.success();
    }

    @PostMapping("/remove")
    public JsonResult remove(@RequestBody  BaseIdsReqVO idsReqVO){
        categoryService.removeBatchByIds(idsReqVO.getIds());

        return ResultTool.success();
    }

    @PostMapping("/update")
    public JsonResult update(@RequestBody BlogCategory category){
        categoryService.upsert(category);

        return ResultTool.success();
    }

    @RequestMapping("/find")
    public JsonResult find(@RequestBody BaseIdReqVO idReqVO){
        return ResultTool.success(categoryService.findById(idReqVO.getId()));
    }

    @RequestMapping("/find/all")
    public JsonResult findAll(){
        return ResultTool.success(categoryService.findAll());
    }

}
